home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / public / plan / src / gotomenu.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  5KB  |  179 lines

  1. /*
  2.  * Create and destroy the goto popup. It is installed when the Goto item
  3.  * View pulldown in the main calendar window is used.
  4.  *
  5.  *    destroy_goto_popup()
  6.  *    create_goto_popup()
  7.  */
  8.  
  9. #include <stdio.h>
  10. #include <time.h>
  11. #include <Xm/Xm.h>
  12. #include <Xm/DialogS.h>
  13. #include <Xm/Form.h>
  14. #include <Xm/RowColumn.h>
  15. #include <Xm/LabelP.h>
  16. #include <Xm/LabelG.h>
  17. #include <Xm/PushBP.h>
  18. #include <Xm/PushBG.h>
  19. #include <Xm/TextF.h>
  20. #include <Xm/Protocols.h>
  21. #include "cal.h"
  22.  
  23. extern time_t parse_datestring();
  24. extern struct tm *time_to_tm();
  25. extern void help_callback();
  26. static void text_callback(), done_callback();
  27.  
  28. extern Display        *display;    /* everybody uses the same server */
  29. extern Pixel        color[NCOLS];    /* colors: COL_* */
  30. extern struct config    config;        /* global configuration data */
  31. extern struct list    *mainlist;    /* list of all schedule entries */
  32. extern int        curr_month;    /* month being displayed, 0..11 */
  33. extern int        curr_year;    /* year being displayed, since 1900 */
  34. extern time_t        curr_week;    /* week being displayed, time in sec */
  35.  
  36. static BOOL        have_shell;    /* message popup exists if TRUE */
  37. static Widget        shell;        /* popup menu shell */
  38. static Widget        text;        /* search string */
  39.  
  40.  
  41. /*
  42.  * destroy a popup. Remove it from the screen, and destroy its widgets.
  43.  * It's too much trouble to keep them for next time.
  44.  */
  45.  
  46. destroy_goto_popup()
  47. {
  48.     if (have_shell)
  49.         XtPopdown(shell);
  50.     have_shell = FALSE;
  51. }
  52.  
  53.  
  54. /*
  55.  * create a goto popup as a separate application shell. When the popup
  56.  * already exists and was just popped down, pop it up and exit. This
  57.  * ensures that it comes up with the same text.
  58.  */
  59.  
  60. create_goto_popup()
  61. {
  62.     Widget            form, radio, w;
  63.     Arg            args[20];
  64.     int            n;
  65.     Atom            closewindow;
  66.  
  67.     if (have_shell) {
  68.         XtPopup(shell, XtGrabNone);
  69.         return;
  70.     }
  71.     n = 0;
  72.     XtSetArg(args[n], XmNdeleteResponse,    XmDO_NOTHING);        n++;
  73.     XtSetArg(args[n], XmNiconic,        False);            n++;
  74.     shell = XtAppCreateShell("Goto Date", "plan",
  75.             applicationShellWidgetClass, display, args, n);
  76. #    ifdef EDITRES
  77.     XtAddEventHandler(shell, (EventMask)0, TRUE, 
  78.              _XEditResCheckMessages, NULL);
  79. #    endif
  80.     set_icon(shell, 1);
  81.     form = XtCreateManagedWidget("gotoform", xmFormWidgetClass,
  82.             shell, NULL, 0);
  83.     XtAddCallback(form, XmNhelpCallback, help_callback, (XtPointer)"goto");
  84.  
  85.     n = 0;
  86.     XtSetArg(args[n], XmNtopAttachment,    XmATTACH_FORM);        n++;
  87.     XtSetArg(args[n], XmNtopOffset,        16);            n++;
  88.     XtSetArg(args[n], XmNleftAttachment,    XmATTACH_FORM);        n++;
  89.     XtSetArg(args[n], XmNleftOffset,    16);            n++;
  90.     w = XtCreateManagedWidget("Date to switch to:", xmLabelWidgetClass,
  91.             form, args, n);
  92.     n = 0;
  93.     XtSetArg(args[n], XmNtopAttachment,    XmATTACH_WIDGET);    n++;
  94.     XtSetArg(args[n], XmNtopWidget,        w);            n++;
  95.     XtSetArg(args[n], XmNtopOffset,        8);            n++;
  96.     XtSetArg(args[n], XmNleftAttachment,    XmATTACH_FORM);        n++;
  97.     XtSetArg(args[n], XmNleftOffset,    16);            n++;
  98.     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);        n++;
  99.     XtSetArg(args[n], XmNrightOffset,    16);            n++;
  100.     XtSetArg(args[n], XmNwidth,        300);            n++;
  101.     XtSetArg(args[n], XmNrecomputeSize,    False);            n++;
  102.     XtSetArg(args[n], XmNpendingDelete,    True);            n++;
  103.     XtSetArg(args[n], XmNhighlightThickness,0);            n++;
  104.     XtSetArg(args[n], XmNbackground,    color[COL_TEXTBACK]);    n++;
  105.     text = XtCreateManagedWidget(" ", xmTextFieldWidgetClass,
  106.             form, args, n);
  107.     XtAddCallback(text, XmNactivateCallback, text_callback,
  108.                         (XtPointer)NULL);
  109.     n = 0;
  110.     XtSetArg(args[n], XmNtopAttachment,    XmATTACH_WIDGET);    n++;
  111.     XtSetArg(args[n], XmNtopWidget,        text);            n++;
  112.     XtSetArg(args[n], XmNtopOffset,        16);            n++;
  113.     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_FORM);        n++;
  114.     XtSetArg(args[n], XmNrightOffset,    16);            n++;
  115.     XtSetArg(args[n], XmNwidth,        80);            n++;
  116.     w = XtCreateManagedWidget("Cancel", xmPushButtonWidgetClass,
  117.             form, args, n);
  118.     XtAddCallback(w, XmNactivateCallback, done_callback, (XtPointer)0);
  119.  
  120.     n = 0;
  121.     XtSetArg(args[n], XmNtopAttachment,    XmATTACH_WIDGET);    n++;
  122.     XtSetArg(args[n], XmNtopWidget,        text);            n++;
  123.     XtSetArg(args[n], XmNtopOffset,        16);            n++;
  124.     XtSetArg(args[n], XmNrightAttachment,    XmATTACH_WIDGET);    n++;
  125.     XtSetArg(args[n], XmNrightWidget,    w);            n++;
  126.     XtSetArg(args[n], XmNrightOffset,    8);            n++;
  127.     XtSetArg(args[n], XmNbottomAttachment,    XmATTACH_FORM);        n++;
  128.     XtSetArg(args[n], XmNbottomOffset,    16);            n++;
  129.     XtSetArg(args[n], XmNwidth,        80);            n++;
  130.     w = XtCreateManagedWidget("Help", xmPushButtonWidgetClass,
  131.             form, args, n);
  132.     XtAddCallback(w, XmNactivateCallback, help_callback,(XtPointer)"goto");
  133.  
  134.     XtPopup(shell, XtGrabNone);
  135.     closewindow = XmInternAtom(display, "WM_DELETE_WINDOW", False);
  136.     XmAddWMProtocolCallback(shell, closewindow,
  137.                     done_callback, (XtPointer)shell);
  138.     have_shell = TRUE;
  139. }
  140.  
  141.  
  142. /*-------------------------------------------------- callbacks --------------*/
  143. /*
  144.  * All of these routines are direct X callbacks.
  145.  */
  146.  
  147. /*ARGSUSED*/
  148. static void done_callback(widget, item, data)
  149.     Widget                widget;
  150.     int                item;
  151.     XmToggleButtonCallbackStruct    *data;
  152. {
  153.     destroy_goto_popup();
  154. }
  155.  
  156.  
  157. /*ARGSUSED*/
  158. static void text_callback(widget, item, data)
  159.     Widget                widget;
  160.     int                item;
  161.     XmToggleButtonCallbackStruct    *data;
  162. {
  163.     String string = XmTextFieldGetString(widget);
  164.     if (*string) {
  165.         time_t time = parse_datestring(string, get_time());
  166.         struct tm *tm = time_to_tm(time);
  167.         curr_month = tm->tm_mon;
  168.         curr_year  = tm->tm_year;
  169.         curr_week  = time - 86400 *
  170.                 (tm->tm_wday - !config.sunday_first);
  171.         draw_month_year();
  172.         draw_calendar();
  173.         draw_week_calendar();
  174.         draw_year_calendar();
  175.     }
  176.     XtFree(string);
  177.     destroy_goto_popup();
  178. }
  179.